package com.baobao.dao;

import com.baobao.domain.Bbevent;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Bbevent entities.
 * 
 */
@Repository("BbeventDAO")
@Transactional
public class BbeventDAOImpl extends AbstractJpaDao<Bbevent> implements
		BbeventDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Bbevent.class }));

	/**
	 * EntityManager injected by Spring for persistence unit BaoBao
	 *
	 */
	@PersistenceContext(unitName = "BaoBao")
	private EntityManager entityManager;

	/**
	 * Instantiates a new BbeventDAOImpl
	 *
	 */
	public BbeventDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findBbeventByType
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByType(Integer type) throws DataAccessException {

		return findBbeventByType(type, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByType
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByType(Integer type, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByType", startResult, maxRows, type);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByBbIdContaining
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByBbIdContaining(String bbId) throws DataAccessException {

		return findBbeventByBbIdContaining(bbId, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByBbIdContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByBbIdContaining(String bbId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByBbIdContaining", startResult, maxRows, bbId);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllBbevents
	 *
	 */
	@Transactional
	public Set<Bbevent> findAllBbevents() throws DataAccessException {

		return findAllBbevents(-1, -1);
	}

	/**
	 * JPQL Query - findAllBbevents
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findAllBbevents(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllBbevents", startResult, maxRows);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByTimeContaining
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByTimeContaining(String time) throws DataAccessException {

		return findBbeventByTimeContaining(time, -1, -1);
	}
	
	/**
	 * JPQL Query - findBbeventByTimeBetween
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByTimeBetween(String bbId,String starttime,String endtime)
			throws DataAccessException {
		
		return findBbeventByTimeBetween(bbId,starttime,endtime, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByTimeContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByTimeContaining(String time, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByTimeContaining", startResult, maxRows, time);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}
	
	/**
	 * JPQL Query - findBbeventByTimeBetween
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByTimeBetween(String bbId,String starttime, String endtime,int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByTimeBetween", startResult, maxRows, bbId,starttime,endtime);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByConfirmTime
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByConfirmTime(String confirmTime) throws DataAccessException {

		return findBbeventByConfirmTime(confirmTime, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByConfirmTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByConfirmTime(String confirmTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByConfirmTime", startResult, maxRows, confirmTime);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByConfirmPhoneContaining
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByConfirmPhoneContaining(String confirmPhone) throws DataAccessException {

		return findBbeventByConfirmPhoneContaining(confirmPhone, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByConfirmPhoneContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByConfirmPhoneContaining(String confirmPhone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByConfirmPhoneContaining", startResult, maxRows, confirmPhone);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByConfirmTimeContaining
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByConfirmTimeContaining(String confirmTime) throws DataAccessException {

		return findBbeventByConfirmTimeContaining(confirmTime, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByConfirmTimeContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByConfirmTimeContaining(String confirmTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByConfirmTimeContaining", startResult, maxRows, confirmTime);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByPrimaryKey
	 *
	 */
	@Transactional
	public Bbevent findBbeventByPrimaryKey(String bbId, String time) throws DataAccessException {

		return findBbeventByPrimaryKey(bbId, time, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByPrimaryKey
	 *
	 */

	@Transactional
	public Bbevent findBbeventByPrimaryKey(String bbId, String time, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findBbeventByPrimaryKey", startResult, maxRows, bbId, time);
			return (com.baobao.domain.Bbevent) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findBbeventByTime
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByTime(String time) throws DataAccessException {

		return findBbeventByTime(time, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByTime(String time, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByTime", startResult, maxRows, time);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByBbId
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByBbId(String bbId) throws DataAccessException {

		return findBbeventByBbId(bbId, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByBbId
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByBbId(String bbId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByBbId", startResult, maxRows, bbId);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * JPQL Query - findBbeventByConfirmPhone
	 *
	 */
	@Transactional
	public Set<Bbevent> findBbeventByConfirmPhone(String confirmPhone) throws DataAccessException {

		return findBbeventByConfirmPhone(confirmPhone, -1, -1);
	}

	/**
	 * JPQL Query - findBbeventByConfirmPhone
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Bbevent> findBbeventByConfirmPhone(String confirmPhone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findBbeventByConfirmPhone", startResult, maxRows, confirmPhone);
		return new LinkedHashSet<Bbevent>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Bbevent entity) {
		return true;
	}


}
